#ifndef __WORD_H__
#define __WORD_H__

#include <map>
#include <vector>
#include <ext/hash_map>
#include <ext/hash_set>

using namespace std;
using __gnu_cxx::hash_map;

static inline size_t td_hash_string(const char* s)
{
	unsigned long h = 0;
	for ( ; *s; ++s)
		h = 5 * h + *s;
	return size_t(h);
}

struct td_string_hash
{
	size_t operator()(const string& s) const
	{
		return td_hash_string(s.c_str());
	}
};

struct Entrorank
{
	float entrol,entror;
	string item;

	const bool operator < (struct Entrorank& ite) const
	{
		return ((entrol+entror) < (ite.entrol + ite.entror));
	}
	/*const void operator = (struct Entrorank& ite) const
	  {
	  entrol = ite.entrol;
	  entror = ite.entror;
	  item = ite.item;
	  }*/
};

typedef map<string, float> ite_rank_map_t;

struct nbr_rank_map_t
{
	pthread_mutex_t l_lock, r_lock;
	ite_rank_map_t *l_neighbor, *r_neighbor;
};

struct localnbr_rank_map_t
{
	ite_rank_map_t *l_neighbor, *r_neighbor;
};

typedef hash_map<string, nbr_rank_map_t*, td_string_hash> neighbor_map_t;
typedef hash_map<string, localnbr_rank_map_t*, td_string_hash> local_neighbor_map_t;
typedef vector<Entrorank> entro_rank_map_t;


void PushAllNeighborAndCalEntropy(const char* , entro_rank_map_t& , 
		const int, const int, const int, const double);
void CalFrequency1(const char* infile, ite_rank_map_t& , const int , const int );
void IndependenceCheck(entro_rank_map_t& , ite_rank_map_t& , ite_rank_map_t& , const float , const float );

#endif
